package org.xb.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.xb.vo.Myuser;
import org.xb.factory.DAOFactory;
import org.xb.vo.Corporation;
public class CorporationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
 public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
	 this.doPost(request, response);
 }
 public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
	   String path="/error/error.jsp";
		String status=request.getParameter("status");
		if(status==null||"".equals(status)){
		request.getRequestDispatcher(path).forward(request,response);
		}
		if("create".equals(status)){
				try {
					this.create(request,response);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
 }
private void create(HttpServletRequest request, HttpServletResponse response)throws Exception,IOException {
    String path="error/error.jsp";
    String cwhere=request.getParameter("cwhere");
    String cname=request.getParameter("cname");
    String crole=request.getParameter("crole");
    String cplay=request.getParameter("cplay");
    String  csystem=request.getParameter("csystem");
    String content=request.getParameter("content");
    String cteacher=request.getParameter("cteacher");
    Myuser user=(Myuser) request.getSession().getAttribute("user");
    Corporation corporation=new Corporation();
    corporation.setCwhere(cwhere);
    corporation.setCname(cname);
    corporation.setCrole(crole);
    corporation.setCplay(cplay);
    corporation.setCsystem(csystem);
    corporation.setContent(content);
    corporation.setCteacher(cteacher);
    corporation.setChost(user);
    try{
	if(DAOFactory.getCorporationDAOInstance().doCreate(corporation)){
		path="";
	}
    }catch(Exception e){
		e.printStackTrace();
	}
	request.getRequestDispatcher(path).forward(request, response);
}
}

